class Container {
    static of (value) {
        return new Container(value);
    }
    constructor (value) {
        this._value = value;
    }
    map(fn) {
        return Container.of(fn(this._value));
    }
}

class MayBe {
    static of(value) {
        return new MayBe(value);
    }

    constructor(value) {
        this._value = value;
    }

    map(fn) {
        // return MayBe.of(fn(this._value));
        return this.isNothing() ? this : MayBe.of(fn(this._value));
    }
    
    isNothing() {
        return this._value === null || this._value === undefined;
    }
}


const fp = require('lodash/fp');

const safeProp = fp.curry(function (x, o) {
    return MayBe.of(o[x]);
});
const user = {
    id: 2,
    name: 'Albert'
};

const ex2 = function(value) {
    return fp.first(value);
};

console.log('ex2', safeProp('name', user).map(fp.first));

